package com.avic.rong.search.adapter.searchHomeDrawerAdapters;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;

import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/20 12:55
 * E-Mail Address：16601203965@163.com
 * 收缩版adapter
 */
public class SearchHomeChuBanSheShrinkRvAdapter extends RecyclerView.Adapter<SearchHomeChuBanSheShrinkRvAdapter.SearchHomeChuBanSheShrinkRvViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    private List<String> list;
    private static int itemCount = 6;

    public SearchHomeChuBanSheShrinkRvAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    public void addItemCount(int num) {
        itemCount = num;
    }

    @NonNull
    @Override
    public SearchHomeChuBanSheShrinkRvViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.view_search_drawer_item, viewGroup, false);
        return new SearchHomeChuBanSheShrinkRvViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final SearchHomeChuBanSheShrinkRvViewHolder holder, int i) {
        holder.tv.setText(list.get(i));
        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.tv.setSelected(true);
                holder.tv.setTextColor(Color.parseColor("#89cf55"));
            }
        });
    }

    @Override
    public int getItemCount() {
        if (list.size() > 6)
            return itemCount;
        else
            return list.size();
    }

    class SearchHomeChuBanSheShrinkRvViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        public SearchHomeChuBanSheShrinkRvViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.searchView_Drawer_Tv_Item);
        }
    }
}
